MAX

The MAX function returns the value of the largest element of Array.

Examples

Example 1

This example prints the maximum value in an array, and the subscript of that value:

; Create a simple two-dimensional array:

D = DIST(100)



; Print the maximum value in array D and its linear subscript:

PRINT, 'Maximum value in array D is:', MAX(D, I)

PRINT, 'The subscript of the maximum value is', I

IDL Output

Maximum value in array D is: 70.7107

The subscript of the maximum value is 5050

Example 2

To convert I to a two-dimensional subscript, use the commands:

IX = I MOD 100

IY = I/100

PRINT, 'The maximum value of D is at location ('+ STRTRIM(IX, 1) $

   + ', ' + STRTRIM(IY, 1) + ')'

IDL Output

The maximum value of D is at location (50, 50)

Syntax

Result = MAX( Array [, Max_Subscript] [, /ABSOLUTE] [, DIMENSION=value] [, MIN=variable] [, /NAN] [, SUBSCRIPT_MIN=variable])

Return Value

Return the largest array element value. The type of the result is the same as the type of Array.

Arguments

Array

The array to be searched.

Max_Subscript

A named variable that, if supplied, is converted to a long integer containing the one-dimensional subscript of the maximum element. Otherwise, the system variable !C is set to the one-dimensional subscript of the maximum element.

Keywords

ABSOLUTE

If this keyword is set, then the absolute value of each element is used when determining the maximum values.This keyword has no effect for arrays of type byte or unsigned integer.

Note: If ABSOLUTE is set then the sign of each value is ignored when searching for the maximum. However, the return value retains the negative sign if the value was indeed negative.

Tip: For complex input, MAX by default only compares the real component of each value. Use the ABSOLUTE keyword to force MAX to compare the absolute value of each value, and to return the complex value corresponding to the maximum absolute value.

DIMENSION

Set this keyword to the dimension over which to find the maximum values of an array. If this keyword is not present or is zero, the maximum is found over the entire array and is returned as a scalar value. If this keyword is present and nonzero, the result is the “slice” of the input array that contains the maximum value element, and the return values for Result, Max_Subscript, MIN, and SUBSCRIPT_MIN will all be arrays of one dimension less than the input array. That is, if the dimensions of Array are N1, N2, N3, and DIMENSION=2, the dimensions of the result are (N1, N3), and element (i,j) of the result contains the maximum value of Array[i, *, j].

For example:

arr = FINDGEN(2,3,2)
PRINT, arr

IDL prints:

0.00000     1.00000

2.00000     3.00000

4.00000     5.00000

 

6.00000     7.00000

8.00000     9.00000

10.0000     11.0000

 

PRINT, MAX(arr, DIMENSION=2)

IDL prints:

4.00000     5.00000

10.0000     11.0000

 

PRINT, MAX(arr, DIMENSION=1)

IDL prints:

1.00000     3.00000     5.00000

7.00000     9.00000     11.0000

MIN

A named variable to receive the value of the minimum array element. If you need to find both the minimum and maximum array values, use this keyword to avoid scanning the array twice with separate calls to MAX and MIN.

NAN

Set this keyword to cause the routine to check for occurrences of the IEEE floating-point values NaN or Infinity in the input data. Elements with the value NaN or Infinity are treated as missing data.

Note: If the MAX function is run on an array containing NaN values and the NAN keyword is not set, the NaN values will still be treated as missing data but a floating-point warning may occur.

SUBSCRIPT_MIN

Set this keyword equal to a named variable that will contain the one-dimensional subscript of the minimum element, the value of which is available via the MIN keyword.

Thread Pool Keywords

This routine is written to make use of IDL’s thread pool, which can increase execution speed on systems with multiple CPUs. The values stored in the !CPU system variable control whether IDL uses the thread pool for a given computation. In addition, you can use the thread pool keywords TPOOL_MAX_ELTS, TPOOL_MIN_ELTS, and TPOOL_NOTHREAD to override the defaults established by !CPU for a single invocation of this routine. See Thread Pool Keywords for details.

Version History

Original

Introduced

6.1

Added ABSOLUTE keyword

8.5.1

Always treat NaN's as missing values.

See Also

ARRAY_INDICES, MIN, WHERE